import { http } from "@/utils/request";
import type { CategoryResponse, Category } from "./types";
// 获取分类列表
export const getCategoryListAPI = (
  page?: number,
  pageSize?: number,
  token?: string
) => {
  return http.get<CategoryResponse>("/category", {
    params: {
      page: page,
      pageSize: pageSize,
    },
    headers: {
      Authorization: `Bearer ${token}`, // 在请求头中携带 token
    },
  });
};

// 添加分类
export const addCategoryAPI = (title: string, token: string) => {
  return http.post(
    "/category",
    {
      title: title,
    },
    {
      headers: { Authorization: `Bearer ${token}` },
    }
  );
};

// 删除分类
export const deleteCategoryAPI = (id: number, token: string) => {
  return http.delete(`/category/${id}`, {
    headers: { Authorization: `Bearer ${token}` },
  });
};

// 编辑分类
export const editCategoryAPI = (id: number, title: string, token: string) => {
  return http.put(
    `/category/${id}`,
    {
      title: title,
    },
    {
      headers: { Authorization: `Bearer ${token}` },
    }
  );
};

// 获取分类
export const getCategoryAPI = (id: number, token: string) => {
  return http.get(`/category/${id}/links`, {
    headers: { Authorization: `Bearer ${token}` },
  });
};

// 查询分类
export const searchCategoryAPI = (title: string, token: string) => {
  return http.get(`/category/${title}/search`, {
    headers: { Authorization: `Bearer ${token}` },
  });
};
